package org.jeecg.modules.flow.sys.util;

import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.net.url.UrlQuery;
import cn.hutool.core.util.CharsetUtil;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;
import java.util.Set;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    // 流程中字符串的处理
 * 创建人员:    zhaojun
 * 创建时间:    2023-10-31
 */
public class FlowStrUtil {

    public static void main(String[] args) {
//        String str = "xxx?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1";

        String str = "";
//        System.out.println(translateParam(str));
//        System.out.println(str);

        System.out.println(removeLastStr(str));
    }

    /**
     * 将固定的str转化为json对象
     *
     * @param str
     * @return
     */
    public static JSONObject translateParam(String str) {
        UrlBuilder builder = UrlBuilder.ofHttp(str, CharsetUtil.CHARSET_UTF_8);
        UrlQuery query = builder.getQuery();
        Map<CharSequence, CharSequence> queryMap = query.getQueryMap();
        Set<CharSequence> keys = queryMap.keySet();
        JSONObject jsonObject = new JSONObject();
        for (CharSequence key : keys) {
            jsonObject.put((String) key, queryMap.get(key));
        }
        return jsonObject;
    }

    /**
     * 移除？后面的字符串
     *
     * @param str
     * @return
     */
    public static String removeLastStr(String str) {
        return str.split("\\?")[0];
    }
}
